package com.social.serviceImpl;

import com.social.dao.UserMapper;
import com.social.pojo.User;
import com.social.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public User selectByUsername(String username) {
        User user = userMapper.selectByUsername(username);
        return user;
    }

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public User queryByUsername(String username) {
        User user = userMapper.queryByUsername(username);
        return user;
    }

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public List<User> selectAll(Integer page, Integer pageNum) {
        List<User> users = userMapper.selectAll(page, pageNum);
        return users;
    }

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public List<User> selectByUser(Integer page, Integer pageNum) {
        List<User> users = userMapper.selectByUser(page, pageNum);
        return users;
    }

    @Override
    public Integer selectCount() {
        Integer count = userMapper.selectCount();
        return count;
    }

    @Override
    public Integer selectCountLike(String realName, String departmentId) {
        if (departmentId == "" || departmentId == null) departmentId = null;
        Integer countLike = userMapper.selectCountLike(realName, departmentId);
        return countLike;
    }

    @Override
    public List<User> selectByUserLike(String realName, String departmentId, Integer page, Integer pageNum) {
        if (departmentId == "" || departmentId == null) departmentId = null;
        List<User> users = userMapper.selectByUserLike(realName, departmentId, page, pageNum);
        return users;
    }

    @Override
    public Integer selectAllCount() {
        Integer integer = userMapper.selectAllCount();
        return integer;
    }

    @Override
    public List<User> selectAlls() {
        List<User> users = userMapper.selectAlls();
        return users;
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        int status = userMapper.deleteByPrimaryKey(id);
        return status;
    }

    @Override
    public int insert(User record) {
        int status = userMapper.insert(record);
        return status;
    }

    @Override
    public int insertSelective(User record) {
        int status = userMapper.insertSelective(record);
        return status;
    }

    @Override
    public User selectByPrimaryKey(Integer id) {
        User user = userMapper.selectByPrimaryKey(id);
        return user;
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        int status = userMapper.updateByPrimaryKeySelective(record);
        return status;
    }

    @Override
    public int updateByPrimaryKey(User record) {
        int status = userMapper.updateByPrimaryKey(record);
        return status;
    }
}
